import requests
import json
import pickle

try:
    url = 'http://t.weather.sojson.com/api/weather/city/'

    city_file = open('Lab3/city.pkl', 'rb')
    city = pickle.load(city_file)
    city_file.close()

    city_name = input("请输入你要查询的城市：")
    city_no=city[city_name]

    response = requests.get(url + city_no)

    d = response.json()

    if(d['status'] == 200):
        print("城市：", d["cityInfo"]["parent"], d["cityInfo"]["city"])
        print("时间：", d["time"], d["data"]["forecast"][0]["week"])
        print("温度：", d["data"]["forecast"][0]["high"], d["data"]["forecast"][0]["low"])
        print("天气：", d["data"]["forecast"][0]["type"])
except ModuleNotFoundError:
    print("请安装requests与urllib3模块!")
